package com.study.design.pattern.pattern.behavioral.strategy;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: gongsl
 * @Date: 2025-03-23 14:31
 * @description: 支付策略工厂类
 */
public class PaymentStrategyFactory {
    private static final Map<String, PaymentStrategy> PAYMENT_STRATEGY_MAP = new HashMap<>();

    static {
        PAYMENT_STRATEGY_MAP.put(PaymentType.ALI, new AlipayStrategy());
        PAYMENT_STRATEGY_MAP.put(PaymentType.WX, new WechatPayStrategy());
    }

    private static final PaymentStrategy UNKNOWN_STRATEGY = new UnknownStrategy();

    private PaymentStrategyFactory() {

    }

    public static PaymentStrategy getPaymentStrategy(String type) {
        PaymentStrategy paymentStrategy = PAYMENT_STRATEGY_MAP.get(type);
        return paymentStrategy == null ? UNKNOWN_STRATEGY : paymentStrategy;
    }

    private interface PaymentType {
        String ALI = "Aipay";
        String WX = "Wechat";
    }
}
